package com.zhijian.medical.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.zhijian.medical.dao.local.DigitalSliceCaseFileCuttingInfoMapper;
import com.zhijian.medical.entity.po.DigitalSliceCaseFileCuttingInfo;
import com.zhijian.medical.entity.vo.request.DigitalSliceCaseFileCuttingInfoSearchVo;
import com.zhijian.medical.entity.vo.response.DigitalSliceCaseFileCuttingInfoVo;
import com.zhijian.medical.service.DigitalSliceCaseFileCuttingInfoService;
import com.zhijian.medical.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 数字切片-切割后的图片信息业务处理层
 *
 * @author HCG
 * @version: 1.0
 * @date 2023-01-11 16:56:47
 */
@Slf4j
@Service
public class DigitalSliceCaseFileCuttingInfoServiceImpl implements DigitalSliceCaseFileCuttingInfoService {

    @Autowired
    private DigitalSliceCaseFileCuttingInfoMapper mapper;

    @Override
    public DigitalSliceCaseFileCuttingInfo selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public DigitalSliceCaseFileCuttingInfoVo selectVoById(Long id) {
        return mapper.selectVoById(id);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Long insert(DigitalSliceCaseFileCuttingInfo digitalSliceCaseFileCuttingInfo) {
        Date now = new Date();
        digitalSliceCaseFileCuttingInfo.setCreateTime(now);
        digitalSliceCaseFileCuttingInfo.setUpdateTime(now);
        return mapper.insert(digitalSliceCaseFileCuttingInfo) > 0 ? digitalSliceCaseFileCuttingInfo.getId() : 0L;
    }

    @Override
    public boolean update(DigitalSliceCaseFileCuttingInfo digitalSliceCaseFileCuttingInfo) {
        Date now = new Date();
        digitalSliceCaseFileCuttingInfo.setUpdateTime(now);
        return mapper.updateByPrimaryKey(digitalSliceCaseFileCuttingInfo) != 0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(DigitalSliceCaseFileCuttingInfo record) {
        Date now = new Date();
        record.setUpdateTime(now);
        return mapper.updateByPrimaryKeySelective(record) != 0;
    }

    @Override
    public Integer count(DigitalSliceCaseFileCuttingInfoSearchVo digitalSliceCaseFileCuttingInfoSearchVo) {
        return mapper.count(digitalSliceCaseFileCuttingInfoSearchVo);
    }

    @Override
    public List<DigitalSliceCaseFileCuttingInfoVo> selectList(DigitalSliceCaseFileCuttingInfoSearchVo digitalSliceCaseFileCuttingInfoSearchVo) {
        return mapper.selectList(digitalSliceCaseFileCuttingInfoSearchVo);
    }

    @Override
    public Page<DigitalSliceCaseFileCuttingInfoVo> selectPage(DigitalSliceCaseFileCuttingInfoSearchVo digitalSliceCaseFileCuttingInfoSearchVo) {
        //先直接查总数
        int count = count(digitalSliceCaseFileCuttingInfoSearchVo);
        //分页
        Page<DigitalSliceCaseFileCuttingInfoVo> page = new Page<>(true, count, digitalSliceCaseFileCuttingInfoSearchVo.getPageNum(), digitalSliceCaseFileCuttingInfoSearchVo.getPageSize());
        digitalSliceCaseFileCuttingInfoSearchVo.setStartIndex(page.getStartIndex());
        page.setPage(true);
        page.setTotalCount(count);
        List<DigitalSliceCaseFileCuttingInfoVo> responseVos = this.selectList(digitalSliceCaseFileCuttingInfoSearchVo);
        page.setData(responseVos);
        return page;
    }

    @Override
    public boolean insertBatch(List<DigitalSliceCaseFileCuttingInfo> entities) {
        return CollectionUtil.isNotEmpty(entities) && mapper.insertBatch(entities) > 0;
    }

}